<?xml version="1.0"?>
<!-- A build file for use by Ant to build Kawa. -->
<!-- Requires Ant 1.6.3 -->
<project name="Kawa" default="default" basedir=".">
  <property environment="env"/>

  <!-- Give the user a chance to override the defaults. -->
  <property file="build.properties"/>

  <property name="version.release" value="3.0"/>
  <property name="version.local" value=""/>
  <property name="version" value="${version.release}${version.local}"/>

  <property name="debug"        value="true" />
  <property name="deprecation"  value="false" />
  <property name="optimize"     value="true" />
  
  <!--
    There was some discussion of using user.dir as a default here.
    The most promising use being for dist.dir (and maybe build.dir).
    But I decided against that for several reasons:
      1) Consistency (don't make a special case).
      2) The user.dir property isn't reliable (some bad JVMs out there).
      3) Ant is not able to handle both absolute and relative paths
         for commandline arguments based on user.dir.  Ant automatically
         handles relative paths relative to basedir, not user.dir.
         As a result, if dist.dir defaulted to user.dir,
         "ant -buildfile ../kawa/build.xml" and
         "ant -buildfile ../kawa/build.xml -Ddist.dir=." 
         would produce different results.
      4) The value of user.dir is not useful when using a Java IDE
         (like NetBeans or JBuilder) since it is the directory that 
         happened to be current when the IDE started.
    So, the only way to use Ant where the current directory (user.dir)
    is not the directory containing the buildfile, you *must* supply
    absolute paths as arguments.  That is:
    "ant -buildfile ../kawa/build.xml -Ddist.dir=`pwd`/."
    The exception is Ant's arguments themselves, which are processed
    as plain Java files and so are relative to the current directory.
  -->
  <property name="src.dir"      value="${basedir}"/>
  <property name="build.dir"    value="${basedir}"/>
  <property name="dist.dir"     value="${build.dir}"/>
  
  <property name="build.tools"        value="${build.dir}/tools"/>
  <property name="build.tmp"          value="${build.dir}/tmp"/>
  <property name="build.preprocessed" value="${build.dir}"/>
  <property name="build.classes"      value="${build.dir}"/>
  
  <property name="dist.kawa.jar"    value="${dist.dir}/lib/kawa.jar"/>

  <condition property="kawa.shell" value="/bin/bash" else="/bin/sh">
    <available file="/bin/bash"/>
  </condition>

  <!-- 
     Set preprocess.overwrite true to force preprocessing.
     Eventually this will be dependency checked.
     For now use "ant clean" if anything changes.
  -->
  <property name="preprocess.overwrite" value="false"/>

  <target name="all" depends="select-java-auto, classes, jar, kawa.sh, kawa.bat"/>

  <target name="default" depends="all"/>

  <target name="classes" 
          depends="java-classes, lib-scm-classes
          , slib-scm-classes, commonlisp-scm-classes, brl-classes
          , xml-classes, servlet-classes, jemacs-classes, android-classes
          , javafx-classes" />
  
  <!-- 
     These are the files that are Kawa.    
     They go in the classpath, jar, and are deleted by clean.
     If additional files (resources like properties and the
     like) are added, something will need to be done so that
     clean will still work when build.classes=src.dir.
  -->
  <fileset id="build.classes" dir="${build.classes}">
     <include name="gnu/**/*.class"/>
     <include name="kawa/**/*.class"/>
  </fileset>
  
  <!-- 
     These are the files that are preprocessed before compiling.    
     In order to allow them to be mixed with the original source,
     we must list them each here.
  -->
  <fileset id="build.preprocessed" dir="${build.preprocessed}">
     <include name="kawa/Version.java"/>
  </fileset>
  
  <fileset id="build.selectjava" dir="${src.dir}">
     <include name="**/*.java"/>
     <or>
        <contains text="BEGIN JAVA" casesensitive="true"/>
        <contains text=" #endif " casesensitive="true"/>
     </or>
  </fileset>

  <target name="run" depends="classes">
     <java taskname="kawa" classname="kawa.repl" classpath="${build.classes}" fork="true"/>
  </target>
  
  <target name="runw" depends="classes">
     <java taskname="kawa" fork="true"
           classname="kawa.repl" classpath="${build.classes}">
       <arg value="-w"/>
     </java>
  </target>
  
  <!--
    This is part of an "if" trick.  Do not change me.
    The "if" attribute for tasks is not true if the property is not
    set at all, not whether the value is "true" or "false".
    So here we use the value of the with- or enable- properties
    and rely on true being "true" with this property defined,
    and false being "false" with that property not defined.
  -->
  <property name="true" value="true"/>

  <target name="build-settings" depends="build-tools">
    <!-- If java.awt.Component is in the classpath, then we'll compile the
       AWT UI, unless you override the setting of with-awt. -->
    <condition property="with-awt" else="false">
      <available classname="java.awt.Component"/>
    </condition>
    
    <!-- If org.xml.sax.ContentHandler is in the classpath, then we'll compile
       in SAX2 support, unless you override the setting of with-sax2.   -->
    <condition property="with-sax2" else="false">
      <available classname="org.xml.sax.ContentHandler"/>
    </condition>

    <!-- If java.awt.Component is in the classpath, then we'll compile the
       JEmacs Swing UI, unless you override the setting of with-swing.  -->
    <condition property="with-swing" else="false">
      <available classname="javax.swing.JComponent"/>
    </condition>

    <!-- JEmacs stuff is compiled if Swing is used, unless enable-jemacs is false.
    -->
    <property name="enable-jemacs" value="false"/>

    <property name="enable-xml" value="true"/>

    <property name="enable-brl" value="false"/>

    <property name="enable-android" value="false"/>

    <property name="javafx.home" value=""/>
    <property name="enable-javafx" value="false"/>
    <condition property="do.enable.javafx">
      <or>
        <istrue value="${enable-javafx}"/>
        <not><equals arg1="${javafx.home}" arg2=""/></not>
      </or>
    </condition>
    <condition property="-use.javafx.home">
      <and>
        <not><equals arg1="${javafx.home}" arg2=""/></not>
        <istrue value="${do.enable.javafx}"/>
      </and>
    </condition>

    <path id="pextra.classpath">
      <fileset dir="${javafx.home}"><include name="rt/lib/jfxrt.jar" if="-use.javafx.home"/></fileset>
    </path>
    <property name="extra.classpath" refid="pextra.classpath"/>
    <path id="build.classpath">
      <pathelement path="${java.class.path}"/>
      <fileset dir="${javafx.home}"><include name="rt/lib/jfxrt.jar" if="-use.javafx.home"/></fileset>
    </path>

    <!-- If javax.servlet.http.HttpServlet is in the classpath, then we'll
         compile Kawa' servlet interface, unless you override enable-servlet.

         The servlet code uses methods from the 2.3 specification now.
         So test for a class that is new for the 2.3 API. -->
    <condition property="enable-servlet" else="false">
      <available classname="javax.servlet.Filter"/>
    </condition>

    <condition property="isWindows">
      <os family="windows" />
    </condition>

    <condition property="classpath.separator" value=";" else=":">
      <os family="windows" />
    </condition>
  
    <condition property="preprocess-xml" value="+enable:XML" else="-enable:XML">
      <istrue value="${enable-xml}"/>
    </condition>

    <condition property="preprocess-awt" value="+use:java.awt" else="-use:java.awt">
      <istrue value="${with-awt}"/>
    </condition>

    <condition property="preprocess-HttpServer" value="+use:com.sun.net.httpserver"
	       else="-use:com.sun.net.httpserver">
      <available classname="com.sun.net.httpserver.HttpServer"/>
    </condition>

    <condition property="with-javax-script" else="false">
      <available classname="javax.script.ScriptEngine"/>
    </condition>

    <condition property="-needs-scripting-inf">
      <and>
        <istrue value="${with-javax-script}"/>
        <not>
          <available file="META-INF/services/javax.script.ScriptEngineFactory"/>
        </not>
      </and>
    </condition>

    <condition property="-needs-scripting-inf-xquery">
      <and>
        <istrue value="${-needs-scripting-inf}"/>
        <istrue value="${enable-xml}"/>
      </and>
    </condition>

    <echo>
        version=${version}
        dist.kawa.jar=${dist.kawa.jar}
        build.dir=${build.dir}
        with-awt=${with-awt}
        with-swing=${with-swing}
        with-sax2=${with-sax2}
        enable-jemacs=${enable-jemacs}
        enable-xml=${enable-xml}
        enable-servlet=${enable-servlet}
        enable-android=${enable-android}
        enable-javafx=${do.enable.javafx}
    </echo>

    <!-- 
       This dummy copy is just so we can reference the sets by id.
       This is needed because we are not able to put linestrippersets
       in a task or project the way we can with filtersets.
       Ant gives "Overriding previous definition of reference to..."
       warnings.  Can't seem to avoid that.
    -->

    <xcopy dataOnly="true">
      <linestripperset id="strip-char-subs">
        <linestripper first="if CHAR is byte" last="endif CHAR is byte" />
      </linestripperset>

    </xcopy>
  </target>
  
  <target name="build-tools">
    <mkdir dir="${build.tools}"/>
    <mkdir dir="${build.tmp}"/>
    <!-- 
      This didn't work in NetBeans for some reason. 
      (Even the includejavaruntime/includeantruntime attributes do no good.
      The really weird thing is that NetBeans has access to the classes
      for autocomplete and the scripting window.  Oh well.)
      The workaround is to link to ant.jar.
    -->
    <javac srcdir="${src.dir}"
           destdir="${build.tools}"
           classpath="lib/ext/ant.jar"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}"
	   includeantruntime="true">
      <include name="gnu/kawa/util/PreProcess.java"/>
      <include name="gnu/kawa/ant/*.java"/>
    </javac>

    <taskdef name="xcopy"
             classname="gnu.kawa.ant.XCopy"
             classpath="${build.tools}"/>
    <taskdef name="kawac"
             classname="gnu.kawa.ant.Kawac"
             classpath="${build.tools}"/>

    <!-- 
       This doesn't really help us because user data 
       definitions don't seem to be possible.
    <typedef name="linestripperset" 
             classname="gnu.kawa.ant.LineStripperSet"
             classpath="${build.tools}"/>
    -->

  </target>

  <available property="has-java2" classname="java.lang.ThreadLocal"/>
  <available property="has-java4" classname="java.lang.CharSequence"/>
  <available property="has-java5" classname="java.lang.Appendable"/>
  <available property="has-java6" classname="javax.script.AbstractScriptEngine"/>
  <available property="has-java7" classname="java.lang.invoke.MethodHandle"/>
  <available property="has-java8" classname="java.util.stream.Stream"/>

  <target name="select-java1" depends="build-settings">
    <pathconvert property="fileList" pathSep=" " dirSep="${file.separator}">
      <path><fileset refid="build.selectjava"/></path>
    </pathconvert>
    <java classname="gnu.kawa.util.PreProcess">
      <classpath location="${build.tools}"/>
      <arg line="%java1 ${preprocess-xml} ${preprocess-awt} -use:com.sun.net.httpserver"/>
      <arg line="${fileList}"/>
    </java>
  </target>
    
  <target name="select-java2" depends="build-settings">
    <pathconvert property="fileList" pathSep=" " dirSep="${file.separator}">
      <path><fileset refid="build.selectjava"/></path>
    </pathconvert>
    <java classname="gnu.kawa.util.PreProcess">
      <classpath location="${build.tools}"/>
      <arg line="%java2 ${preprocess-xml} ${preprocess-awt} -use:com.sun.net.httpserver"/>
      <arg line="${fileList}"/>
    </java>
  </target>
    
  <target name="select-java4" depends="build-settings">
    <pathconvert property="fileList" pathSep=" " dirSep="${file.separator}">
      <path><fileset refid="build.selectjava"/></path>
    </pathconvert>
    <java classname="gnu.kawa.util.PreProcess">
      <classpath location="${build.tools}"/>
      <arg line="%java4 ${preprocess-xml} ${preprocess-awt} -use:com.sun.net.httpserver"/>
      <arg line="${fileList}"/>
    </java>
  </target>
    
  <target name="select-java5" depends="build-settings">
    <pathconvert property="fileList" pathSep=" " dirSep="${file.separator}">
      <path><fileset refid="build.selectjava"/></path>
    </pathconvert>
    <java classname="gnu.kawa.util.PreProcess">
      <classpath location="${build.tools}"/>
      <arg line="%java5 ${preprocess-xml} ${preprocess-awt} -use:com.sun.net.httpserver"/>
      <arg line="${fileList}"/>
    </java>
  </target>
    
  <target name="select-java6" depends="build-settings">
    <pathconvert property="fileList" pathSep=" " dirSep="${file.separator}">
      <path><fileset refid="build.selectjava"/></path>
    </pathconvert>
    <java classname="gnu.kawa.util.PreProcess">
      <classpath location="${build.tools}"/>
      <arg line="%java6 ${preprocess-xml} ${preprocess-awt} ${preprocess-HttpServer}"/>
      <arg line="${fileList}"/>
    </java>
  </target>

  <target name="select-android" depends="build-settings">
    <pathconvert property="fileList" pathSep=" " dirSep="${file.separator}">
      <path><fileset refid="build.selectjava"/></path>
    </pathconvert>
    <java classname="gnu.kawa.util.PreProcess">
      <classpath location="${build.tools}"/>
      <arg line="%android ${preprocess-xml} ${preprocess-awt} -use:com.sun.net.httpserver"/>
      <arg line="${fileList}"/>
    </java>
  </target>
    
  <target name="select-java7" depends="build-settings">
    <pathconvert property="fileList" pathSep=" " dirSep="${file.separator}">
      <path><fileset refid="build.selectjava"/></path>
    </pathconvert>
    <java classname="gnu.kawa.util.PreProcess">
      <classpath location="${build.tools}"/>
      <arg line="%java7 ${preprocess-xml} ${preprocess-awt} ${preprocess-HttpServer}"/>
      <arg line="${fileList}"/>
    </java>
  </target>

  <target name="select-java8" depends="build-settings">
    <pathconvert property="fileList" pathSep=" " dirSep="${file.separator}">
      <path><fileset refid="build.selectjava"/></path>
    </pathconvert>
    <java classname="gnu.kawa.util.PreProcess">
      <classpath location="${build.tools}"/>
      <arg line="%java8 ${preprocess-xml} ${preprocess-awt} ${preprocess-HttpServer}"/>
      <arg line="${fileList}"/>
    </java>
  </target>

  <target name="-maybe-select-java1" unless="has-java2">
    <antcall target="select-java1"/>
  </target>
  <target name="-maybe-select-java2" if="has-java2" unless="has-java4">
    <antcall target="select-java2"/>
  </target>
  <target name="-maybe-select-java4" if="has-java4" unless="has-java5">
    <antcall target="select-java4"/>
  </target>
  <target name="-maybe-select-java5" if="has-java5" unless="has-java6">
    <antcall target="select-java5"/>
  </target>
  <target name="-maybe-select-java6" if="has-java6" unless="has-java7">
    <antcall target="select-java6"/>
  </target>
  <target name="-maybe-select-java7" if="has-java7" unless="has-java8">
    <antcall target="select-java7"/>
  </target>
  <target name="-maybe-select-java8" if="has-java8">
    <antcall target="select-java8"/>
  </target>
  <target name="-maybe-select-android" if="${enable-android}">
    <antcall target="select-android"/>
  </target>

  <target name="select-java-auto">
    <antcall target="-select-java-non-android"/>
    <antcall target="-maybe-select-android"/>
  </target>

  <target name="-select-java-non-android" unless="${enable-android}">
    <antcall target="-maybe-select-java1"/>
    <antcall target="-maybe-select-java2"/>
    <antcall target="-maybe-select-java4"/>
    <antcall target="-maybe-select-java5"/>
    <antcall target="-maybe-select-java6"/>
    <antcall target="-maybe-select-java7"/>
    <antcall target="-maybe-select-java8"/>
  </target>
  
  <!-- 
     This preprocessing jazz is rather involved and verbose,
     but it is entirely compatible with the makefile code 
     and actually _isn't_ as complicated as I could have made 
     it (as there are still unrolled patterns here that could 
     have been wrapped up but I demurred in consideration of 
     those who may try and grok it).
  -->

      <filterset id="filter-do-not-edit" begintoken="-*-" endtoken="-*-">
        <filter token="Java" 
          value="Automatically generated file - DO NOT EDIT!.  -*- buffer-read-only: t -*-" />
      </filterset>
      
  <target name="preprocess" depends="build-tools, build-settings">
    <mkdir dir="${build.preprocessed}"/>

    <xcopy todir="${build.preprocessed}/kawa" 
           overwrite="${preprocess.overwrite}">
      <fileset dir="${src.dir}/kawa" includes="*.java.in"/>
      <mapper type="glob" from="*Version.java.in" to="*Version.java"/>
      <filterset refid="filter-do-not-edit"/>
      <filterset begintoken="&quot;" endtoken="&quot;">
        <filter token="VERSION" value="&quot;${version}&quot;" />
      </filterset>
    </xcopy>

  </target>

  <target name="-make-primvector-source">
    <java classname="gnu.kawa.util.PreProcess">
      <classpath location="${build.tools}"/>
      <arg value="%${TAG}"/>
      <arg value="%UniformVector"/>
      <arg value="-o"/>
      <arg value="gnu/lists/${OUT}Vector.java"/>
      <arg value="gnu/lists/PrimVector.template"/>
    </java>
  </target>

  <target name="-maybe-generate-simplevector-files" unless="simplevector-files-uptodate">
    <antcall target="-make-primvector-source">
      <param name="TAG" value="OBJECT"/>
      <param name="OUT" value="F"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="BIT"/>
      <param name="OUT" value="Bit"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="BYTE"/>
      <param name="OUT" value="Byte"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="SHORT"/>
      <param name="OUT" value="Short"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="INT"/>
      <param name="OUT" value="Int"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="LONG"/>
      <param name="OUT" value="Long"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="F32"/>
      <param name="OUT" value="F32"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="F64"/>
      <param name="OUT" value="F64"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="S8"/>
      <param name="OUT" value="S8"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="S16"/>
      <param name="OUT" value="S16"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="S32"/>
      <param name="OUT" value="S32"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="S64"/>
      <param name="OUT" value="S64"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="U8"/>
      <param name="OUT" value="U8"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="U16"/>
      <param name="OUT" value="U16"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="U32"/>
      <param name="OUT" value="U32"/>
    </antcall>
    <antcall target="-make-primvector-source">
      <param name="TAG" value="U64"/>
      <param name="OUT" value="U64"/>
    </antcall>
  </target>

  <target name="generate-simplevector-files" depends="build-tools">
    <uptodate property="simplevector-files-uptodate">
      <srcfiles file="${src.dir}/gnu/lists/PrimVector.template"/>
      <srcfiles file="${build.tools}/gnu/kawa/util/PreProcess.class"/>
      <compositemapper>
        <mergemapper to="${src.dir}/gnu/lists/FVector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/BitVector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/ByteVector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/ShortVector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/IntVector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/LongVector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/F32Vector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/F64Vector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/S8Vector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/S16Vector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/S32Vector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/S64Vector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/U8Vector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/U16Vector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/U32Vector.java"/>
        <mergemapper to="${src.dir}/gnu/lists/U64Vector.java"/>
      </compositemapper>
    </uptodate>

    <antcall target="-maybe-generate-simplevector-files"/>
  </target>

  <target name="kawa.sh" depends="build-settings">
    <copy file="${src.dir}/bin/kawa.sh.in" tofile="bin/kawa.sh">
      <filterset>
        <filter token="ENABLE_KAWA_FRONTEND_TRUE" value="#"/>
        <filter token="VERSION" value="${version}"/>
        <filter token="CLASSPATH_SEPARATOR" value="${classpath.separator}"/>
        <filter token="KAWAJAR" value="kawa.jar"/>
        <filter token="CYGPATH_W" value="echo"/>
        <filter token="KAWA_SHELL" value="${kawa.shell}"/>
        <filter token="conf_classpath" value=""/>
      </filterset>
    </copy>
    <chmod file="bin/kawa.sh" perm="+x"/>
  </target>
  
  <patternset id="with-sax2-false">
  </patternset>

  <patternset id="with-sax2-true">
    <include name="gnu/kawa/sax/"/>
  </patternset>

  <patternset id="with-awt-true"/>
  
  <patternset id="with-awt-false">
    <exclude name="kawa/GuiConsole.java"/>
    <exclude name="kawa/MessageArea.java"/>
    <exclude name="kawa/TextAreaWriter.java"/>
    <exclude name="kawa/GuiInPort.java"/>
  </patternset>
  
  <target name="java-classes" depends="preprocess,generate-simplevector-files">
    <mkdir dir="${build.classes}"/>
    <!-- 
       Javac doesn't "shadow" directories, so there may not be duplicates.
       That means that if you're building other than in the source directory,
       then the source directory must be clean.
    -->
    <javac srcdir="${build.preprocessed}:${src.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}"
	   includeantruntime="false">
      <include name="gnu/bytecode/"/>
      <include name="gnu/commonlisp/lang/"/>
      <include name="gnu/ecmascript/"/>
      <include name="gnu/expr/"/>
      <exclude name="gnu/expr/AbstractScriptEngineFactory.java" unless="has-java6"/>
      <exclude name="gnu/expr/KawaScriptBindings.java" unless="has-java6"/>
      <exclude name="gnu/expr/KawaScriptEngine.java" unless="has-java6"/>
      <exclude name="kawa/standard/SchemeScriptEngineFactory.java" unless="has-java6"/>
      <include name="gnu/kawa/functions/"/>
      <include name="gnu/kawa/lispexpr/*.java"/>
      <exclude name="gnu/kawa/lispexpr/MakeXmlElement.java" unless="${enable-xml}"/>
      <exclude name="gnu/kawa/lispexpr/ReaderXmlElement.java" unless="${enable-xml}"/>
      <exclude name="gnu/kawa/lispexpr/ResolveNamespace.java" unless="${enable-xml}"/>
      <include name="gnu/kawa/reflect/"/>
      <include name="gnu/kawa/util/"/>
      <include name="gnu/lists/"/>
      <include name="gnu/mapping/"/>
      <include name="gnu/math/"/>
      <include name="gnu/q2/lang/"/>
      <include name="gnu/text/"/>
      <include name="kawa/lang/"/>
      <include name="kawa/standard/"/>
      <include name="kawa/repl.java"/>
      <include name="kawa/Shell.java"/>
      <include name="kawa/Version.java"/>
      <include name="kawa/Source*.java"/>
      <include name="kawa/Telnet*.java"/>
      <include name="kawa/Gui*.java" if="${with-swing}"/>
      <include name="kawa/Repl*.java" if="${with-swing}"/>
      <include name="gnu/kawa/xml/"/>
      <include name="gnu/xml/"/>
      <patternset refid="with-awt-${with-awt}"/>
      <include name="gnu/kawa/models/" if="${with-awt}"/>
      <include name="gnu/kawa/swingviews/" if="${with-swing}"/>
    </javac>
  </target>
   
  <!-- 
    Can't use apply's dependency checking because
    Kawa can't handle a "-C" with no files listed.
    Also that is probably the wrong thing because
    Kawa needs all the files listed for its scanning.
  -->

  <target name="lib-scm-classes" 
          depends="java-classes">
    <kawac failonerror="true" destdir="${build.classes}"
	   prefix="kawa.lib." modulestatic="run" language="scheme">
      <arg line="--warn-undefined-variable --warn-unknown-member --warn-as-error"/>
      <filelist dir="${src.dir}/kawa/lib">
        <file name="prim_imports.scm"/>
        <file name="prim_syntax.scm"/>
        <file name="std_syntax.scm"/>
        <file name="reflection.scm"/>
        <file name="syntax.scm"/>
        <file name="lists.scm"/>
        <file name="case_syntax.scm"/>
        <file name="DefineRecordType.scm"/>
        <file name="ExceptionClasses.scm"/>
        <file name="exceptions.scm"/>
        <file name="kawa/expressions.scm"/>
        <file name="compile_misc.scm"/>
        <file name="compile_map.scm"/>
        <file name="thread.scm"/>
        <file name="characters.scm"/>
        <file name="keywords.scm"/>
        <file name="numbers.scm"/>
        <file name="strings_syntax.scm"/>
        <file name="strings.scm"/>
        <file name="parameters.scm"/>
        <file name="parameterize.scm"/>
        <file name="ports.scm"/>
        <file name="files.scm"/>
        <file name="misc.scm"/>
        <file name="misc_syntax.scm"/>
        <file name="vectors.scm"/>
        <file name="uniform.scm"/>
        <file name="bytevectors.scm"/>
        <file name="arrays.scm"/>
        <file name="system.scm"/>
        <file name="kawa/istrings.scm"/>
        <file name="kawa/mstrings.scm"/>
        <file name="kawa/arglist.scm"/>
        <file name="kawa/process-keywords.scm"/>
        <file name="kawa/string-cursors.scm"/>
        <file name="kawa/hashtable.scm"/>
        <file name="kawa/regex.scm"/>
        <file name="rnrs/unicode.scm"/>
        <file name="scheme/base.scm"/>
        <file name="scheme/case-lambda.scm"/>
        <file name="scheme/char.scm"/>
        <file name="scheme/complex.scm"/>
        <file name="scheme/cxr.scm"/>
        <file name="scheme/eval.scm"/>
        <file name="scheme/file.scm"/>
        <file name="scheme/inexact.scm"/>
        <file name="scheme/lazy.scm"/>
        <file name="scheme/load.scm"/>
        <file name="scheme/process-context.scm"/>
        <file name="scheme/read.scm"/>
        <file name="scheme/repl.scm"/>
        <file name="scheme/time.scm"/>
        <file name="scheme/write.scm"/>
        <file name="scheme/r5rs.scm"/>
        <file name="trace.scm"/>
      </filelist>
    </kawac>
    <kawac failonerror="true" destdir="${build.classes}"
	   prefix="kawa.lib." modulestatic="run" language="scheme">
      <arg line="--warn-undefined-variable --warn-unknown-member --warn-as-error"/>
      <filelist dir="${src.dir}/kawa/lib">
        <file name="enums.scm"/>
        <file name="srfi/8.scm"/>
        <file name="srfi/26.scm"/>
        <file name="srfi/95.scm"/>
        <file name="strings_ext.scm"/>
        <file name="rnrs/hashtables.scm"/>
        <file name="rnrs/lists.scm"/>
        <file name="rnrs/arithmetic/bitwise.scm"/>
        <file name="rnrs/sorting.scm"/>
        <file name="rnrs/programs.scm"/>
        <file name="kawa/base.scm"/>
      </filelist>
      <fileset dir="${src.dir}/kawa/lib">
        <include name="kawa/pictures.scm" if="${with-awt}"/>
        <include name="windows.scm" if="${with-swing}"/>
        <include name="kawa/swing.scm" if="${with-swing}"/>
      </fileset>
    </kawac>
    <kawac failonerror="true" destdir="${build.classes}"
	   prefix="kawa.lib." modulestatic="run" language="scheme">
      <arg line="--warn-undefined-variable --warn-unknown-member --warn-as-error"/>
      <filelist dir="${src.dir}/kawa/lib">
        <file name="kawa/quaternions.scm"/>
        <file name="kawa/pprint.scm"/>
        <file name="kawa/rotations.scm"/>
        <file name="kawa/null-5.scm"/>
        <file name="kawa/reflect.scm"/>
      </filelist>
    </kawac>
  </target>

  <target name="commonlisp-scm-classes"
          depends="java-classes">
    <kawac failonerror="true" destdir="${build.classes}"
	   prefix="gnu.commonlisp.lisp." modulestatic="run" language="scheme">
       <filelist dir="${src.dir}/gnu/commonlisp/lisp">
         <file name="PrimOps.scm"/>
       </filelist>
    </kawac>
    <kawac failonerror="true" destdir="${build.classes}"
	   prefix="gnu.commonlisp.lisp." modulestatic="run" language="clisp">
       <filelist dir="${src.dir}/gnu/commonlisp/lisp">
         <file name="primitives.lisp"/>
       </filelist>
    </kawac>
  </target>

  <target name="slib-scm-classes" depends="java-classes">
    <kawac failonerror="true" destdir="${build.classes}"
	   prefix="gnu.kawa.slib." modulestatic="run"
	   language="scheme">
      <filelist dir="${src.dir}/gnu/kawa/slib">
        <file name="readtable.scm"/>
        <file name="srfi1.scm"/>
        <file name="srfi2.scm"/>
        <file name="conditions.scm"/>
        <file name="srfi13.scm"/>
        <file name="srfi14.scm"/>
        <file name="srfi34.scm"/>
        <file name="srfi37.scm"/>
        <file name="srfi60.scm"/>
        <file name="srfi69.scm"/>
        <file name="pregexp.scm"/>
        <file name="Streams.scm"/>
        <file name="StreamsDerived.scm"/>
        <file name="StreamsPrimitive.scm"/>
        <file name="StreamsType.scm"/>
        <file name="genwrite.scm"/>
        <file name="pp.scm"/>
        <file name="ppfile.scm"/>
        <file name="printf.scm"/>
        <file name="syntaxutils.scm"/>
        <file name="testing.scm"/>
      </filelist>
      <fileset dir="${src.dir}/gnu/kawa/slib">
        <include name="gui.scm" if="${with-awt}"/>
        <include name="swing.scm" if="${with-swing}"/>
      </fileset>
    </kawac>
  </target> 

  <target name="xml-classes"
          depends="build-settings, java-classes" 
          if="${enable-xml}">
    <javac srcdir="${src.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}"
	   includeantruntime="false">
      <include name="gnu/xml/"/>
      <include name="gnu/kawa/xml/"/>
      <include name="gnu/kawa/xslt/"/>
      <include name="gnu/xquery/lang/"/>
      <exclude name="gnu/xquery/lang/XQueryScriptEngineFactory.java" unless="has-java6"/>
      <include name="gnu/xquery/util/"/>
      <patternset refid="with-sax2-${with-sax2}"/>
    </javac>
    <kawac failonerror="true" destdir="${build.classes}"
	    prefix="gnu.kawa.slib."  modulestatic="run" language="scheme">
      <fileset dir="${src.dir}/gnu/kawa/slib"> 
        <include name="XML.scm"/>
        <include name="XStrings.scm"/>
      </fileset>
    </kawac>
    <kawac failonerror="true" destdir="${build.classes}"
	    prefix="gnu.xquery.util."  modulestatic="run" language="scheme">
      <fileset dir="${src.dir}/gnu/xquery/util"> 
        <include name="Xutils.scm"/>
      </fileset>
    </kawac>
  </target>

  <target name="brl-classes"
          depends="build-settings, java-classes" 
          if="${enable-brl}">
    <javac srcdir="${src.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}"
	   includeantruntime="false">
      <include name="gnu/brl/"/>
      <include name="gnu/kawa/brl/"/>
      <patternset refid="with-sax2-${with-sax2}"/>
    </javac>
    <kawac failonerror="true" destdir="${build.classes}"
	    prefix="gnu.brl."  modulestatic="run" language="scheme">
      <fileset dir="${src.dir}/gnu/brl"> 
        <include name="stringfun.scm"/>
      </fileset>
    </kawac>
    <kawac failonerror="true" destdir="${build.classes}"
	    prefix="gnu.kawa.brl."  modulestatic="run" language="scheme">
      <fileset dir="${src.dir}/gnu/kawa/brl"> 
        <include name="progfun.scm"/>
      </fileset>
    </kawac>
  </target>

  <target name="javafx-classes"
          depends="build-settings, java-classes" 
          if="${do.enable.javafx}">
    <javac srcdir="${src.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}"
           classpathref="build.classpath"
	   includeantruntime="false">
      <include name="gnu/kawa/javafx/"/>
    </javac>
    <kawac failonerror="true" destdir="${build.classes}"
           classpathref="build.classpath"
           prefix="gnu.kawa.javafx."  modulestatic="run" language="scheme">
      <fileset dir="${src.dir}/gnu/kawa/javafx"> 
        <include name="defs.scm"/>
        <include name="GroupObjectBuilder.scm"/>
        <include name="MakeScene.scm"/>
      </fileset>
    </kawac>
  </target>

  <target name="servlet-classes" 
          depends="build-settings, java-classes" 
          if="${enable-servlet}">
    <javac srcdir="${src.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}"
	   includeantruntime="false">
      <include name="gnu/kawa/servlet/"/>
    </javac>
    <apply taskname="kawa" executable="java" 
           failonerror="true" parallel="true">
      <!-- I don't quite get why the Java classpath has to be tacked on here, but it does. -->
      <arg value="-classpath"/> <arg path="${build.classes}:${java.class.path}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P gnu.kawa.slib. --module-static-run -C"/>
      <fileset dir="${src.dir}/gnu/kawa/servlet"> 
        <include name="HTTP.scm"/>
      </fileset>
    </apply>
  </target>
   
  <target name="android-classes" 
          depends="build-settings, java-classes" 
          if="${enable-android}">
    <fail message="android.path (value: ${android.path}) is not a file">
      <condition>
        <not><available file="${android.path}"/></not>
      </condition>
    </fail>
    <apply taskname="kawa" executable="java" 
           failonerror="true" parallel="true">
      <!-- I don't quite get why the Java classpath has to be tacked on here, but it does. -->
      <arg value="-classpath"/> <arg path="${android.path}:${build.classes}:${java.class.path}"/>
      <arg value="kawa.repl"/>
      <arg value="-d"/> <arg path="${build.classes}"/>
      <arg line="-P gnu.kawa.android. --module-static-run -C"/>
      <fileset dir="${src.dir}/gnu/kawa/android"> 
        <include name="utils.scm"/>
        <include name="defs.scm"/>
        <include name="ViewBuilder.scm"/>
      </fileset>
    </apply>
  </target>

  <target name="jemacs-java-classes" 
          depends="build-settings, java-classes" 
          if="${enable-jemacs}">
    <javac srcdir="${src.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}"
	   includeantruntime="false">
      <include name="gnu/jemacs/buffer/"/>
      <include name="gnu/jemacs/lang/"/>
      <include name="gnu/jemacs/swing/" if="${with-swing}"/>
    </javac>
  </target>

  <target name="jemacs-swt-classes" depends="jemacs-classes">
    <javac srcdir="${src.dir}" destdir="${build.classes}"
	   includeantruntime="false">
      <include name="gnu/jemacs/swt/"/>
    </javac>
  </target>

  <target name="jemacs-classes" 
          depends="build-settings, java-classes, jemacs-java-classes"
          if="${enable-jemacs}">

    <kawac failonerror="true" destdir="${build.classes}"
	    prefix="gnu.kawa.slib" modulestatic="run" language="scheme">
      <fileset dir="${src.dir}/gnu/kawa/slib"> 
	<include name="gui.scm"/>
      </fileset>
    </kawac>

    <kawac failonerror="true" destdir="${build.classes}"
           prefix="gnu.jemacs.lisp." language="scheme">
      <filelist dir="${src.dir}/gnu/jemacs/lisp">
        <file name="MiscOps.scm"/>
        <file name="NumberOps.scm"/>
        <file name="emacs.scm"/>
      </filelist>
    </kawac>

    <kawac failonerror="true" destdir="${build.classes}"
	    prefix="gnu.jemacs.lisp." language="elisp">
      <filelist dir="${src.dir}/gnu/jemacs/lisp">
        <file name="primitives.el"/>
        <file name="alist.el"/>
        <file name="simple.el"/>
        <file name="keymap.el"/>
        <file name="keydefs.el"/>
        <file name="hanoi.el"/>
        <file name="rect.el"/>
        <file name="editfns.el"/>
        <file name="subr.el"/>
        <file name="autoloads.el"/>
      </filelist>
    </kawac>
  </target>

  <target name="script-factory-scheme" if="${-needs-scripting-inf}">
    <mkdir dir="META-INF/services"/>
    <echo message="kawa.standard.SchemeScriptEngineFactory #Scheme&#xA;"
          append="true"
          file="META-INF/services/javax.script.ScriptEngineFactory"/>
  </target>
  <target name="script-factory-xquery" if="${-needs-scripting-inf-xquery}">
    <mkdir dir="META-INF/services"/>
    <echo message="gnu.xquery.lang.XQueryScriptEngineFactory #XQuery&#xA;"
          append="true"
          file="META-INF/services/javax.script.ScriptEngineFactory"/>
  </target>

  <target name="jar" depends="script-factory-scheme,script-factory-xquery">
    <jar jarfile="${dist.kawa.jar}"
         manifest="${src.dir}/jar-manifest">
      <fileset refid="build.classes"/>
      <fileset dir="${build.classes}">
        <include name="META-INF/services/*"/>
      </fileset>
    </jar>
  </target>

  <target name="kawa.bat" depends="build-settings" if="isWindows">
    <copy file="bin/kawa.bat.in" toFile="bin/kawa.bat">
      <filterset begintoken="%" endtoken="%">
        <filter token="DEFAULT_KAWA_VERSION" value="${version}"/>
        <filter token="DEFAULT_EXTRA_PATH" value="${extra.classpath};"/>
      </filterset>
    </copy>
  </target>

  <!--
    These clean targets are split up for when
    get build-tools doesn't work in NetBeans.
    (There is a workaround now, see build-tools.)
    For this to work, build.tools must be a different
    directory than build.classes uses.
  -->
  <target name="clean-build">
    <delete>
       <fileset refid="build.classes"/>
       <fileset refid="build.preprocessed"/>
       <fileset file="bin/kawa.bat"/>
       <fileset file="bin/kawa.sh"/>
    </delete>
    <delete dir="META-INF"/>
  </target>

  <target name="clean-generated-simplevector-files">
    <delete>
      <fileset dir="${src.dir}/gnu/lists"
               includes="FVector.java
                         BitVector.java
                         ByteVector.java
                         ShortVector.java
                         IntVector.java
                         LongVector.java
                         F32Vector.java
                         F64Vector.java
                         S8Vector.java
                         S16Vector.java
                         S32Vector.java
                         S64Vector.java
                         U8Vector.java
                         U16Vector.java
                         U32Vector.java
                         U64Vector.java">
      </fileset>
    </delete>
  </target>

  <target name="clean-tools">
    <delete dir="${build.tools}"/>
  </target>

  <target name="clean-dist">
    <delete file="${dist.kawa.jar}"/>
  </target>

  <target name="clean" depends="clean-build, clean-tools, clean-dist"/>

</project>
